#include <iostream>
#include <queue>
#include <vector>

using namespace std;

const int N = 1e4 + 10;
vector<int> edges[N];
int len[N];
int in[N], f[N];
int n;

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int x, y;
		cin >> x >> len[x];
		while (cin >> y, y)
		{
			edges[y].push_back(x);
			in[x]++;
		}
	}
	queue<int> q;
	for (int i = 1; i <= n; i++)
	{
		if (in[i] == 0) q.push(i);
	}
	int ans = 0;
	while (q.size())
	{
		int t = q.front(); q.pop();
		f[t] += len[t];
		ans = max(ans, f[t]);
		for (auto x : edges[t])
		{
			f[x] = max(f[x], f[t]);
			--in[x];
			if (in[x] == 0) q.push(x);
		}
	}

	cout << ans << endl;

	return 0;
}
